# -*- coding: utf-8 -*-
"""
Created on Mon Apr 22 18:13:45 2019

@author: ikaros
"""

def two_txts_merge(file1,file2,file3):
    """
    利用python进行文件内容合并成新文件。
    要求：mergeTXT.txt，first.txt，second.txt三个文件都要存在，
         若mergeTXT.txt文件不存在时，运行的结果可能只生成这个文件，不进行写入，
         需要再运行一次才写入。
    """              
    """
    file1 = 'first.txt'
    file2 = 'second.txt'
    file3 = 'mergeTXT.txt'
    """
    first=[]
    second=[]
    with open(file1, 'r') as f1:
        for line in f1:
            line=line.strip()
            first.append(line)
    with open(file2, 'r') as f2:
        for line2 in f2:
            line2=line2.strip()
            second.append(line2)
    with open(file3,'w') as f:    
        for i in range(10):
            result=first[i]+':\t'+second[i]+'\n' # 合并成一行，用制表符分隔
            f.write(result)
            
def add_txt_content(file1,content):
    """
    file1 = 'result.txt'
    content is a string
    """
    content = content + '\n'
    with open(file1, "a") as f:
        f.write(content)